<!DOCTYPE html>
<html lang="zh-CN">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>

  <div id="app">

    <!-- 1. 字符串拼接 Mustache语法 -->
    <!-- ps: 不推荐，语法过于繁琐，代码看着乱 -->
    <h3>{{ name1 + name2 }}</h3>
    <hr>

    <!-- 2. 通过定义methods -->
    <!-- ps: 通过测试得知，每写一个getFullName函数都会调用一次，会浪费浏览器加载资源  -->
    <h3>{{ getFullName() }}</h3>
    <h3>{{ getFullName() }}</h3>
    <hr>

    <!-- 3. 通过computed -->
    <!-- ps: 通过测试得知，computed计算属性会存在缓存，调用一次后，下次调用将直接使用缓存数据 -->
    <h3>{{ fullName }}</h3>
    <h3>{{ fullName }}</h3>

  </div>

  <script src="../../js/vue.js"></script>
  <script>
    const app = new Vue({
      el: '#app',
      data: {
        name1: "Mr.chen",
        name2: "Mrs.cao"
      },

      methods: {
        getFullName: function () {
          console.log("我是methods哟~ ");
          return this.name1 + ' ' + this.name2;
        }
      },

      computed: {
        fullName: function () {
          console.log("我是computed哟~ ");
          return this.name1 + ' ' + this.name2;
        }
      }
    })
  </script>
</body>

</html>